//routes/person.js使用的中间件
//获取用户列表
const testList=(req,res,next)=>{
//  res.send({message:'person.js的中间件走通了！'})
//参数验证
//获取参数
const {current,pagesize,is_status,gender,search}=req.query
//验证
if(!(current===undefined||!isNaN(current))) return next(5)
if(!(pagesize===undefined||!isNaN(pagesize))) return next(5)
if(!(/^(all|1|0|undefined)$/.test(is_status))) return next(5)
if(!(/^(all|男|女|保密|undefined)$/.test(gender))) return next(5)

// console.log(current,pagesize,is_status,gender,search);
if(current===undefined)req.query.current=1
if(pagesize===undefined)req.query.pagesize=20
if(is_status===undefined)req.query.is_status='all'
if(gender===undefined)req.query.gender='all'
if(search===undefined)req.query.search=''
// res.send({message:req.query})
next()
}
//修改用户中间件
const testStatus=(req,res,next)=>{
    // res.send({message:'修改状态中间件'})
    // 拿到用户的信息
    const {id,status}=req.body
    // console.log(id,status);
    //参数验证
    if(id.length!==24) return next(5)
    if(!(status==='1'||status==='0'))return next(5)
    next()
}
module.exports={
    testList,
    testStatus
}